package com.zlzxm.lock;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.widget.RemoteViews;

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

/**
 * Created by zlz
 * on  2019-10-14
 */
public class LockService extends Service {

    public static final String TAG = LockService.class.getSimpleName();

    private ScreenReceiver screenReceiver;

    @Override
    public void onCreate() {
        super.onCreate();

        screenReceiver = new ScreenReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.SCREEN_OFF");
        filter.addAction("android.intent.action.SCREEN_ON");
        registerReceiver(screenReceiver, filter);
        createNotification();

    }

    private void createNotification() {

        String channelID= "lock";

        String channelName = "锁屏提醒";

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.remoteview);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel(channelID,
                    channelName,NotificationManager.IMPORTANCE_HIGH);

            notificationManager.createNotificationChannel(notificationChannel);
        }

        Notification notification = new NotificationCompat.Builder(this,channelID)
                .setContent(remoteView).setSmallIcon(R.mipmap.ic_launcher).build();


        startForeground(1,notification);
//
//        Notification notification2 = new NotificationCompat.Builder(this,channelID).build();
//
//
//        startForeground(2,notification2);


    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);

    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
}
